package com.qhg.saas_server.controller;


import com.github.pagehelper.PageInfo;
import com.qhg.saas_server.annotation.Mylog;
import com.qhg.saas_server.empty.Result;
import com.qhg.saas_server.pojo.dto.VisitLogDto;
import com.qhg.saas_server.pojo.dto.VisitStatisticsDto;
import com.qhg.saas_server.service.VisitLogService;
import com.qhg.saas_server.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/VisitLog")
@Slf4j
@Api("拜访模块接口")
@CrossOrigin
public class VisitLogController {

    @Autowired
    VisitLogService visitLogService;

    @ApiOperation("条件分页查询拜访结果查询")
    @PostMapping("/getVisitLog")
    public Result getVisitLogByCondition(@RequestBody VisitLogDto visitLogDto){

        PageInfo<VisitLogDto> pageInfo = visitLogService.getVisitLogByCondition(visitLogDto);

        return Result.success(pageInfo);

    }

    @ApiOperation("根据条件导出拜访结果的excel文件")
    @PostMapping("/exportVisitLog")
    @Mylog("根据条件导出拜访结果的excel文件")
    public  void exportVisitLogByConditon(@RequestBody VisitLogDto visitLogDto, HttpServletResponse response){

        PageInfo<VisitLogDto> pageInfo = visitLogService.getVisitLogByCondition(visitLogDto);
        List<VisitLogDto> list = pageInfo.getList();
        ExcelUtil.exportExcel(list,"拜访结果查询","sheet1",VisitLogDto.class,"VisitLog.xls",response);

    }

    @ApiOperation("选择导出拜访结果的excel文件")
    @PostMapping("/selectExportVisitLog")
    @Mylog("选择导出拜访结果的excel文件")
    public  void  selectExportVisitLog(@RequestBody List<Integer> visitLogIdList ,HttpServletResponse response){

        //根据VisitLogIdList查询VisitLogDtoList
        List<VisitLogDto> visitLogDtoList = visitLogService.selectVisitLogDtoListByVisitLogIdList(visitLogIdList);
        //导出excel文件
        ExcelUtil.exportExcel(visitLogDtoList,"拜访结果查询","sheet1",VisitLogDto.class,"VisitLog.xls",response);

    }

    @ApiOperation("拜访统计条件查询")
    @PostMapping("/getVisitLogPlus")
    public Result getVisitLogPlusByCondition(@RequestBody VisitStatisticsDto visitStatisticsDto){

//        log.info(visitStatisticsDto.toString());

        PageInfo<VisitStatisticsDto> visitLogPlusByCondition = visitLogService.getVisitLogPlusByCondition(visitStatisticsDto);

        return Result.success(visitLogPlusByCondition);

    }


    @ApiOperation("根据条件导出拜访统计")
    @PostMapping("/exportVisitLogPlus")
    @Mylog("根据条件导出拜访统计")
    public void exportVisitLogPlus(@RequestBody VisitStatisticsDto visitStatisticsDto,HttpServletResponse response){

        PageInfo<VisitStatisticsDto> pageInfo = visitLogService.getVisitLogPlusByCondition(visitStatisticsDto);
        List<VisitStatisticsDto> list = pageInfo.getList();
        ExcelUtil.exportExcel(list,"拜访统计","sheet1",VisitStatisticsDto.class,"VisitLogPlus.xls",response);

    }




}
